package com.blink.optimize.apis.string;

import com.google.common.base.Splitter;
import org.junit.jupiter.api.Test;

import java.util.StringTokenizer;

/**
 * <Description> </Description>
 * <ClassName> TestSplit</ClassName>
 *
 * @Author liuxianzhao
 * @Date 2018年01月08日 15:06
 */
public class TestSplit {

    private static final int count = 1_000_000;

    @Test
    public void testStringSplit() {
        String str = "2018-01-01";
        long start = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
            str.split("-");
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    @Test
    public void testStringTokenizer() {
        String str = "2018-01-01";
        long start = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
            StringTokenizer stringTokenizer = new StringTokenizer(str, "-");
            while (stringTokenizer.hasMoreElements()) {
                stringTokenizer.nextToken();
            }
        }
        System.out.println(System.currentTimeMillis() - start);
    }

    @Test
    public void testGuavaSplitter() {
        String str = "2018-01-01";
        long start = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
            Splitter.on("_").split(str);
        }
        System.out.println(System.currentTimeMillis() - start);
    }

}
